package cn.lysj.framework.common.validate.validate;

import cn.lysj.framework.common.validate.annotation.Number;
import cn.lysj.framework.common.validate.entity.Entity;

import java.math.BigDecimal;

public class NumberValidate extends AbstractValidate<Number> {
    public boolean validate(Entity entity) {
        try {
            String arg = String.valueOf(entity.getValue());
            new BigDecimal(arg);
        } catch (Exception e) {
            return  false;
        }
        return true;
    }

    public void init() {
        this.setMsg(annotation.message());
        this.setGroups(annotation.groups());
    }
}
